package utils

import (
	"Junior_two/subject/common"
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"strconv"
	"time"
)

var redisClient *redis.Client

func init() {
	redisClient = common.RedisClient()
}

func SetSms(key string, code int) bool {
	_, err := redisClient.Set(context.Background(), key, strconv.Itoa(code), 5*time.Minute).Result()
	if err != nil {
		fmt.Println(err)
		return false
	}
	return true
}

func GetSms(key string) (string, bool) {
	str, err := redisClient.Get(context.Background(), key).Result()
	if err != nil {
		fmt.Println(err)
		return "", false
	}
	return str, true
}
